home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Text Processing / Alpha 5.63 / Tcl / SystemCode / think.tcl < prev    next >
Encoding:
Text File  |  1993-11-20  |  6.3 KB  |  292 lines  |  [TEXT/ALFA]

  1.  
  2. # The commands so far are:
  3. #     "thinkNumFiles"                         - Returns number of files in project.
  4. #     "thinkFileName <index>|<name>"             - Indexes start at '1'.
  5. #     "thinkCompileFile <options> <filename>"    - With no options, the action is to 
  6. #                                               compile the named file.
  7. #             -2    tell Think not to open windows for output. Output is tossed.
  8. #             -c    precompile
  9. #             -d    dissasemble
  10. #            -g    run
  11. #            -m    make
  12. #             -n    use source file even for "make". This is because sending a project
  13. #                 object descriptor w/ the make command does nothing. Sending a
  14. #                 descriptor for an individual source file w/ the make command makes 
  15. #                 the entire project. Don't ask me.
  16. #             -p    preprocess
  17. #             -r <0|1>    Wait for reply if '1', don't wait for '0'. Default for all
  18. #                except precompile and disassemble, because these two are *supposed*
  19. #                to return their text.
  20. #             -s    check syntax.
  21. #            -u     bring up-to-date.
  22. #     
  23. # "thinkCompileFile -m -n <any of the file names>" seems to make the entire project.
  24.  
  25.  
  26.  
  27. # Get list of files in current project.
  28. proc projectFileList args {
  29.     watchCursor
  30.     set num [thinkNumFiles]
  31.     set files {}
  32.     if {[llength $args]} {
  33.         for {set i 1} {$i<=$num} {incr i} {
  34.             lappend files [thinkFileName -p $i]
  35.         }
  36.     } else {
  37.         for {set i 1} {$i<=$num} {incr i} {
  38.             lappend files [thinkFileName $i]
  39.         }
  40.     }
  41.     return $files
  42. }
  43.  
  44.  
  45.  
  46. # Think reference 2.0 support. From the shell:
  47. #    dosc -c 'DanR' -k 'DanR' -e "'REF '" -s "PutScrap"
  48. # tells think reference to find and display the correct reference.
  49. #    dosc -c 'DanR' -k 'DanR' -e 'TMPL' -s "PutScrap"
  50. # queries Think Reference for a function template and IM reference,
  51. # and displays information about the function in the background.
  52. # The following function interprets the selected text as a function 
  53. # name and displays in an alert the function template.
  54. proc thinkReferenceTemplate args {
  55.     if {[getPos] == [selEnd]} return
  56.     catch {dosc -c 'DanR' -k 'DanR' -e 'TMPL' -s [getSelect]} res
  57.     alertnote $res
  58. }
  59.  
  60. proc add {} {
  61.     thinkAddFile [lindex [winNames -f] 0]
  62. }
  63.  
  64. proc addAndCompile {} {
  65.     add
  66.     compile
  67. }
  68.  
  69. proc compile {} {
  70.     watchCursor
  71.     thinkCompileFile -c -r [lindex [winNames] 0]
  72. }
  73.  
  74. proc checkSyntax {} {
  75.     watchCursor
  76.     thinkCompileFile -s -r [lindex [winNames] 0]
  77. }
  78.  
  79. proc disassemble {} {
  80.     watchCursor
  81.     thinkCompileFile -d -r [lindex [winNames] 0]
  82. }
  83.  
  84. proc preprocess {} {
  85.     "Think isn't quite there yet..."
  86.     return
  87.     watchCursor
  88.     thinkCompileFile -z [lindex [winNames] 0]
  89. }
  90.  
  91. proc precompile {} {
  92.     watchCursor
  93.     thinkCompileFile -p -r [lindex [winNames] 0]
  94. }
  95.  
  96. proc bringUpToDate {} {
  97.     watchCursor
  98.     thinkCompileFile -u -r
  99. }
  100.  
  101. proc make {} {
  102.     watchCursor
  103.     thinkCompileFile -m -r
  104. }
  105.  
  106. proc run {} {
  107.     set name [checkRunning ThinkC KAHL thinkName]
  108.     thinkCompileFile -g
  109.     switchTo $name
  110. }
  111.  
  112.  
  113.  
  114. #================================================================================
  115. set lastTrap {}
  116.  
  117. proc insertTrapTemplate {} {
  118.     global lastTrap
  119.  
  120.     if {![string length [checkRunning ThinkReference DanR referencePath]]} return
  121.     set text [getSelect]
  122.     if {![string length $text]} {
  123.         if {[catch {prompt "Trap name:" $lastTrap} text]} return
  124.     } else {
  125.         deleteText [getPos] [selEnd]
  126.     }
  127.     set lastTrap $text
  128.     if {[catch {thinkReference -t $text} out]} {
  129.         alertnote "THINK Reference not running..."
  130.     } else {
  131.         insertText $out
  132.     }
  133. }
  134.  
  135. proc displayTrapTemplate {} {
  136.     global lastTrap
  137.  
  138.     if {![string length [checkRunning ThinkReference DanR referencePath]]} return
  139.     set text {}
  140.     catch {set text [getSelect]}
  141.     if {![string length $text]} {
  142.         if {[catch {prompt "Trap name:" $lastTrap} text]} return
  143.     }
  144.     set lastTrap $text
  145.     if {[catch {thinkReference -t $text} out]} {
  146.         alertnote "THINK Reference not running..."
  147.     } else {
  148.         alertnote $out
  149.     }
  150. }
  151.  
  152. proc lookupTrap {} {
  153.     global lastTrap
  154.  
  155.     if {![string length [checkRunning ThinkReference DanR referencePath]]} return
  156.     set text {}
  157.     catch {set text [getSelect]}
  158.     if {![string length $text]} {
  159.         if {[catch {prompt "Trap name:" $lastTrap} text]} return
  160.     }
  161.     set lastTrap $text
  162.     if {[catch {thinkReference -l aesend $text}]} {
  163.         alertnote "THINK Reference not running..."
  164.     }
  165. }
  166.  
  167. proc gotoReference {} {
  168.     switchTo [checkRunning ThinkReference DanR referencePath]
  169. }
  170.  
  171. menu -n "•265" {
  172.     "gotoReference"
  173.     "(-"
  174.     "displayTrapTemplate"
  175.     "insertTrapTemplate"
  176.     "lookupTrap"
  177. }
  178.  
  179. #================================================================================
  180.  
  181.  
  182. proc think {} {
  183.     set name [checkRunning ThinkC KAHL thinkName]
  184.     if {![string length $name]} return
  185.     switchTo $name
  186. }
  187.  
  188. proc findInNextFile {} {
  189.     thinkFinf
  190. }
  191.  
  192.  
  193. # The 'Files' menu can instantiate itself from the THINK Project Manager if 
  194. # it is running. 
  195. menu -n "•300" {
  196.     "/-think"
  197.     "openHeader"
  198.     "setIncludepath…"
  199.     "(-"
  200.     {menu -n {Project Files} {
  201.         "getProjectFiles"}}
  202.     "createProjectFileset"
  203.     "(-"
  204.     "/Kcompile"
  205.     "checkSyntax"
  206.     "findInNextFile"
  207.     "(-"
  208.     "add"
  209.     "addAndCompile"
  210.     "(-"
  211.     "disassemble"
  212.     "preprocess"
  213.     "(precompile"
  214.     "(-"
  215.     "/UbringUpToDate"
  216.     "make"
  217.     "(-"
  218.     "/Rrun"
  219. }
  220.  
  221. proc getProjectFiles args {
  222.     menu -n {Project Files} -m -p projFile [lsort [projectFileList -p]]
  223. }
  224.  
  225. proc projFile {menu name} {
  226.     edit [thinkFileName $name]
  227. }
  228.  
  229.  
  230. #===========================================================================
  231. # Add fileset.
  232. #===========================================================================
  233. proc createProjectFileset {} {
  234.     global fileSets
  235.     global currFileSet
  236.     
  237.     set name "Project"
  238.     set fileSets($name) [projectFileList]
  239.     addMenuItem -m fileSets $name
  240.     set currFileSet $name
  241. }
  242.  
  243. #================================================================================
  244.  
  245. proc checkIncludepath {} {
  246.     global includePath
  247.     set bad 0
  248.     if {![info exists includePath]} {return [setIncludepath]}
  249.     foreach p [subVars $includePath] {
  250.         if {![file exists $p]} {set bad 1}
  251.     }
  252.     if ($bad) setIncludepath
  253. }
  254.  
  255. proc setIncludepath {} {
  256.     global includePath HOME
  257.     
  258.     set includePath {}
  259.     
  260.     while {[string length [set path [get_directory]]]} {
  261.         lappend includePath $path
  262.     }
  263.     
  264.     set fid [open "$HOME:Tcl:SystemCode:definitions.tcl" "a"]
  265.     puts $fid "set includePath \"$includePath\""
  266.     close $fid
  267. }
  268.  
  269. proc openHeader {} {
  270.     global includePath
  271.  
  272.     checkIncludepath
  273.     set path [subVars $includePath]
  274.     set fname [getSelect]
  275.     if {[string last ".h" $fname]=="-1"} {
  276.         set fname ${fname}.h
  277.     }
  278.     set win [lindex [winNames -f] 0]
  279.     if {[string match *:* $win]} {
  280.         lappend path [file dirname $win]
  281.     }
  282.     foreach dir $path {
  283.         if {[file exists $dir:$fname]} {
  284.             edit $dir:$fname
  285.             return
  286.         }
  287.     }
  288.     beep
  289.     message "No such header file"
  290. }
  291.